'use strict';

angular.module('backofficeApp.login.controllers',[]).
	controller('loginCtrl',['$scope','$rootScope','$location','$http',function($scope,$rootScope,$location,$http){
	      $("#menu_control_display").css("display","none");
		//登录
		$scope.submit = function (user) {
			$http.post('http://' + backOfficeHost + '/rest/v1.0/backoffice/admin/login',user, {
				headers: {'Content-Type': 'application/json;charset=utf-8'}
			}).success(function (result) {
				if(result.data!=null&&result.data.length>0){//如果用户名和密码都正确，则进入index页面
					$scope.showError=false;
					sessionStorage.setItem("isAuthenticated","true");
					$location.path('/index');
				      $("#menu_control_display").css("display","block");
				      var sdata = JSON.stringify(result.data);
				      sessionStorage.setItem("leftMenuData",sdata);
				      gObj.leftObj.paint(result.data);
				      $("#user_message").css("display","block");
				}else{//如果登录不成功，则进入登录页面
					$scope.showError=true;
					$scope.errorMessage = 'Incorrect loginId or password!...';
					sessionStorage.setItem("isAuthenticated","false");
				}
			}).error(function () {

			});
		};
		//输入用户名
		$scope.changeUserNameValue = function (){
			$scope.showError=false;
		};
		//输入用户口令
		$scope.changePasswordValue = function (){
			$scope.showError=false;
		};
}]);